"""
链式队列,也是先入先出
	思路:
		基于链表构建队列模型
		链表的开端作为队头,结尾位置作为队尾
		单独定义队尾标记,避免每次插入数据遍历
		当队头和队尾重叠,认为队列为空
"""

class QueueError(Exception):
	"""自定义队列异常"""
	pass


class Node:
	"""节点类"""
	def __init__(self, value, next_=None):
		self.value = value  # 有效数据
		self.next_ = next_  # 记录head关系


class LQueue:
	"""队列操作"""
	def __init__(self):
		"""定义 队头和队尾 的属性变量"""
		self.front = self.rear = Node(None)

	def is_empty(self):
		"""判断是否为空"""
		return self.front == self.rear

	def enqqueue(self, value):
		"""入队 rear 动"""
		self.rear.next_ = Node(value)
		self.rear = self.rear.next_

	def dequeue(self):
		"""出队 front 动"""
		if self.front == self.rear:
			raise QueueError("队列为空!")
		self.front = self.front.next_
		return self.front.value


if __name__ == '__main__':
	lq = LQueue()
	for i in range(2, 5):
		lq.enqqueue(i)
	print(lq.dequeue())
